package com.CTAtracker.android.Fragments;

import java.util.ArrayList;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.CTAtracker.android.R;
import com.CTAtracker.android.Adapters.FavoriteStopAdapter;
import com.CTAtracker.android.DAO.FavoriteDataSource;
import com.CTAtracker.android.Models.StopETA;

/**
 * The Fragment regarding the favorite station of the user
 */
public class FavoritesFragment extends Fragment {

	/**
	 * Link to the favorite database
	 */
	private FavoriteDataSource _favoriteDataSource;
	/**
	 * The list view to create and handle 
	 */
	private ListView _listViewFavorite; 
	/**
	 * List of favorite stop
	 */
	private ArrayList<StopETA> _listStopETA;
	
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    	_favoriteDataSource = new FavoriteDataSource(getActivity());
        return inflater.inflate(R.layout.favorites, container, false);
    }

	@Override
	public void onStart() {
		super.onStart();
		_favoriteDataSource.open();
		 _listStopETA = _favoriteDataSource.getAllFavoriteStops(); 
		_favoriteDataSource.close();

		_listViewFavorite = (ListView) getView().findViewById(R.id.favoriteListView);
		FavoriteStopAdapter favoriteAdapter = new FavoriteStopAdapter(getActivity(), R.layout.favorites_adapter, _listStopETA);
		_listViewFavorite.setAdapter(favoriteAdapter);
	}

	@Override
	public void onResume() {
		super.onResume();
		_favoriteDataSource.open();
		 _listStopETA = _favoriteDataSource.getAllFavoriteStops(); 
		_favoriteDataSource.close();

		_listViewFavorite = (ListView) getView().findViewById(R.id.favoriteListView);
		FavoriteStopAdapter favoriteAdapter = new FavoriteStopAdapter(getActivity(), R.layout.favorites_adapter, _listStopETA);
		_listViewFavorite.setAdapter(favoriteAdapter);
	}
	
	
}
